<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <title>主页</title>
    <link href="${pageContext.request.contextPath}/static/css/bootstrap.min.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/static/js/jquery-3.6.0.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js"></script>
    <script>
        window.onload = function () {
            //获取第一个选项
            document.getElementById("firstCb").onclick = function () {
                var check = document.getElementsByName("topicTypeIds");
                for (let i = 0; i < check.length; i++) {
                    check[i].checked = this.checked;
                }
            }
        }
    </script>


</head>
<body>
<div class="container" style="width: 600px;">
    <h1>欢迎光临<security:authentication property="name"/></h1>
    <form action="${pageContext.request.contextPath}/logout" method="post">
        <security:csrfInput/>
        <button type="submit" class="btn btn-default">注销登录</button>
    </form>
    <ul class="nav nav-tabs">
        <li role="presentation" class="active"><a href="#">Home</a></li>
        <li role="presentation"><a href="${pageContext.request.contextPath}/Student/getGrade/${sessionScope.user.id}">考试系统</a>
        </li>
        <li role="presentation"><a href="${pageContext.request.contextPath}/Student/getTests">查看所有考试</a></li>
    </ul>
    <c:if test="${topicType==null}"><h3 style="text-align: center">某人暂时还没想好这里要怎么搞,先留白<br>
    </h3>
        <h4 style="text-align: center"><a href="${pageContext.request.contextPath}/Test/getTopicType">自动出卷</a></h4>
        <h4 style="text-align: center"><a href="${pageContext.request.contextPath}/Test/getExam">定义考试</a></h4>
        <div class="form-group">
            <a href="${pageContext.request.contextPath}/Test/downloadTemplate">获取试题模板</a>
            <form action="${pageContext.request.contextPath}/Test/upload" enctype="multipart/form-data" method="post">
                <security:csrfInput/>
                <label for="exampleInputFile">试卷导入</label>
                <input type="file" name="file" id="exampleInputFile">
                <input class="btn btn-default btn-sm" type="submit" value="Input">
            </form>
        </div>
    </c:if>


    <c:if test="${topicType!=null}">
        <form method="post" action="${pageContext.request.contextPath}/Test/autoTest">
            <security:csrfInput/>
            <table class="table">
                <tr>
                    <th><input type="checkbox" id="firstCb"></th>
                    <th>编号</th>
                    <th>类型</th>
                    <th>描述</th>
                    <th>选择题数</th>
                    <th>填空题数</th>
                    <th>简答题数</th>
                </tr>
                <c:forEach items="${topicType}" var="topicType" varStatus="s">
                    <tr>
                        <td><input type="checkbox" name="topicTypeIds" value="${topicType.id}"></td>
                        <td>${s.count}</td>
                        <td>${topicType.name}</td>
                        <td>${topicType.context}</td>
                        <td>${topicType.choiceCount}</td>
                        <td>${topicType.fillCount}</td>
                        <td>${topicType.shortAnswerCount}</td>
                    </tr>
                </c:forEach>
            </table>
            选择题 : <input type="number" name="choiceCount" value="0"><br>
            填空题 : <input type="number" name="fillCount" value="0"><br>
            简答题 : <input type="number" name="shortAnswerCount" value="0"><br><br>
            试卷描述 :<br>
            <input type="text" class="form-control input-lg" name="context"><br>
            总分 :<br>
            <input type="number" name="score"><br><br>
            <button type="submit" class="btn btn-default">确定</button>
            <a class="btn btn-default" href="${pageContext.request.contextPath}/Test/getTopicType" role="button">取消</a>
        </form>
    </c:if>
</div>
</body>
</html>
